﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Xlit.Project.Entity.Domain;

namespace Xlit.Example.Data
{
    public class ExampleDbContext : DbContext
    {
        public DbSet<Sys_Account> Sys_Account { get; set; }
        public DbSet<Sys_AccountRole> Sys_AccountRole { get; set; }
        public DbSet<Sys_Menu> Sys_Menu { get; set; }
        public DbSet<Sys_Role> Sys_Role { get; set; }
        public DbSet<Sys_RoleMenu> Sys_RoleMenu { get; set; }
        public DbSet<Sys_RolePermission> Sys_RolePermission { get; set; }
        public DbSet<Sys_Orgnization> Sys_Orgnization { get; set; }
        public DbSet<Sys_AccountOrgnization> Sys_AccountOrgnization { get; set; }
        public DbSet<Sys_Notify> Sys_Notify { get; set; }
        public DbSet<Sys_Config> Sys_Config { get; set; }


        public IConfiguration Configuration { get; }

        /// <summary>
        ///  将属性配置注入到这里
        /// </summary>
        /// <param name="options"></param>
        /// <param name="tenantProvider">租户号提供器</param>
        public ExampleDbContext(IConfiguration configuration, DbContextOptions<ExampleDbContext> options) : base(options)
        {
            Configuration = configuration;
        }

        /// <summary>
        ///  如果不用注入的话, 也可以使用这种方式
        /// </summary>
        /// <param name="optionsBuilder"></param>
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseMySql(Configuration.GetConnectionString("ExampleDbContext"));
            }
        }
    }
}
